#ifndef WRAPPER_BaseCmdParam_H
#define WRAPPER_BaseCmdParam_H
#include "file_utilits.h"
#include "cmdline.h"

namespace gdface {
	// client 运行参数配置基类
	class BaseClientConfig {
	public:
		static const int REDIS_DEFAULT_PORT = 6379;
		static const int MQTT_DEFAULT_PORT = 1883;
		const std::string DEFAULT_HOST = "localhost";
		const std::string PARAM_HOST_NAME = "host";
		const std::string PARAM_PORT_NAME = "port";
		cmdline::parser cmdparam;
		std::string host;
		int port;
		int defaultPort;
		BaseClientConfig(int defaultPort = REDIS_DEFAULT_PORT) :port(0), defaultPort(defaultPort){
			cmdparam.add<std::string>(PARAM_HOST_NAME, 'h', "host name", false, DEFAULT_HOST);
			cmdparam.add<int>(PARAM_PORT_NAME, 'p', "port number", false, defaultPort, cmdline::range(1, 65535));
		}
		void parse(int argc, char*argv[]) {
			auto program_name = get_file_name(argv[0]);
			cmdparam.set_program_name(program_name);
			cmdparam.parse_check(argc, argv);
			afterParse();
		}
		virtual ~BaseClientConfig() = default;
	protected:
		virtual void afterParse() {
			host = cmdparam.get<std::string>(PARAM_HOST_NAME);
			port = cmdparam.get<int>(PARAM_PORT_NAME);
		}
	};
} /* namespace gdface */
#endif // !WRAPPER_BaseCmdParam_H


